package bobaini.com.old;


/**
 * if-else代码太繁琐，建议使用策略模式
 * 1: 定义一个接口
 * 2：定义不同的行为去实现这个接口
 */
public class ShareFactory {

    public static void main(String[] args) throws Exception {
        Integer shareType = 1;
        // 测试业务逻辑
        if (shareType.equals(ShareType.SINGLE.getCode())) {
            SingleItemShare singleItemShare = new SingleItemShare();
            singleItemShare.algorithm("单商品");
        } else if (shareType.equals(ShareType.MULTI.getCode())) {
            MultiItemShare multiItemShare = new MultiItemShare();
            multiItemShare.algorithm("多商品");
        } else if (shareType.equals(ShareType.ORDER.getCode())) {
            OrderItemShare orderItemShare = new OrderItemShare();
            orderItemShare.algorithm("下单");
        } else {
            throw new Exception("未知分享类型");
        }
    }
}

